project(yagf C CXX)
cmake_minimum_required(VERSION 2.6.0)
# Setting MPTIFF_SUPPORT to true turns on the multi-image tiffs support. In this case YAGF requires various libtiff development files
# that may are incompatible with the Qt's JPEG reader on some systems. So Qt (and YAGF) may lose the ability to read jpegs.
# You have been warned!
set(MPTIFF_SUPPORT false)
if(MPTIFF_SUPPORT)
set(TIFFIO_SRC src/qxttiffiohandler.cpp)
endif(MPTIFF_SUPPORT)
if (NOT DEFINED  ${CMAKE_INSTALL_PREFIX})
set(CPACK_INSTALL_PREFIX /usr/)
set (CMAKE_INSTALL_PREFIX /usr/)
endif()
# following 2 lines define where interface translations will be installed
set(QML_DESTINATION share/yagf/translations/)
set(QML_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX})
add_definitions( -DQML_INSTALL_PATH="${QML_INSTALL_PREFIX}${QML_DESTINATION}")
set(SOURCES src/main.cpp src/mainform.cpp src/qgraphicsinput.cpp src/utils.cpp src/qxtunixsignalcatcher.cpp src/spellchecker.cpp src/BlockAnalysis.cpp src/PageAnalysis.cpp
    src/SkewAnalysis.cpp src/CCAnalysis.cpp src/qxtgraphicsproxywidget.cpp src/popplerdialog.cpp src/pdfextractor.cpp src/pdf2ppt.cpp src/ghostscr.cpp 
    src/configdialog.cpp src/advancedconfigdialog.cpp src/ccbuilder.cpp src/analysis.cpp src/qsnippet.cpp src/sidebar.cpp src/droplabel.cpp src/projectmanager.cpp src/settings.cpp
    src/texteditor.cpp src/tblock.cpp src/tpage.cpp src/tpagecollection.cpp ${TIFFIO_SRC} src/scanner.cpp src/imagebooster.cpp src/forcelocaledialog.cpp)
set(HEADERS src/settings.h)
set(INT_SOURCES src/preload.c)
set(UIS src/mainform.ui src/popplerdialog.ui src/configdialog.ui src/advancedconfigdialog.ui src/forcelocaledialog.ui)
set(MOC_HEADERS src/mainform.h src/qxtunixsignalcatcher.h src/qxtunixscinternal.h src/qgraphicsinput.h src/qxtgraphicsproxywidget.h src/qxtgraphicsview.h
    src/popplerdialog.h src/pdfextractor.h src/pdf2ppt.h src/configdialog.h src/advancedconfigdialog.h src/ccbuilder.h src/qsnippet.h src/sidebar.h
    src/droplabel.h src/projectmanager.h src/texteditor.h src/tblock.h src/tpage.h src/tpagecollection.h src/scanner.h src/imagebooster.h src/forcelocaledialog.h)
set (yagf_RCCS src/yagf.qrc)
set(QM_FILES ${CMAKE_BINARY_DIR}/yagf_ru.qm ${CMAKE_BINARY_DIR}/yagf_lt.qm ${CMAKE_BINARY_DIR}/yagf_de.qm ${CMAKE_BINARY_DIR}/yagf_pl.qm ${CMAKE_BINARY_DIR}/yagf_uk.qm)
set (LIB_PATH_SUFFIX )
add_definitions(-Wall -g)
find_package(Qt4 4.6 REQUIRED)
find_package(ASPELL REQUIRED)
if(MPTIFF_SUPPORT)
add_definitions(-DTIFF_IO)
find_package(TIFF REQUIRED)
endif(MPTIFF_SUPPORT)
include(${QT_USE_FILE})
qt4_wrap_ui(UI_HEADERS ${UIS})
qt4_wrap_cpp(MOC_SRCS ${MOC_HEADERS})
qt4_add_resources(yagf_RCC_SRCS ${yagf_RCCS})
include_directories( ${CMAKE_BINARY_DIR} ${PROJECT_SOURCE_DIR}/src)
add_executable(yagf ${SOURCES} ${UI_HEADERS} ${MOC_SRCS} ${yagf_RCC_SRCS} ${QM_FILES})
add_library(xspreload SHARED ${INT_SOURCES})
target_link_libraries(xspreload dl)
target_link_libraries(yagf ${QT_LIBRARIES} ${ASPELL_LIBRARIES} ${TIFF_LIBRARIES})
add_custom_target(translations DEPENDS ${QM_FILES})
qt4_add_translation(${CMAKE_BINARY_DIR}/yagf_ru.qm ${PROJECT_SOURCE_DIR}/src/mainform.cpp ${PROJECT_SOURCE_DIR}/src/popplerdialog.cpp ${MOC_SRCS} ${UI_HEADERS} ${PROJECT_SOURCE_DIR}/src/translations/yagf_ru.ts)
qt4_add_translation(${CMAKE_BINARY_DIR}/yagf_lt.qm ${PROJECT_SOURCE_DIR}/src/mainform.cpp ${PROJECT_SOURCE_DIR}/src/popplerdialog.cpp ${MOC_SRCS} ${UI_HEADERS} ${PROJECT_SOURCE_DIR}/src/translations/yagf_lt.ts)
qt4_add_translation(${CMAKE_BINARY_DIR}/yagf_de.qm ${PROJECT_SOURCE_DIR}/src/mainform.cpp ${PROJECT_SOURCE_DIR}/src/popplerdialog.cpp ${MOC_SRCS} ${UI_HEADERS} ${PROJECT_SOURCE_DIR}/src/translations/yagf_de.ts)
qt4_add_translation(${CMAKE_BINARY_DIR}/yagf_pl.qm ${PROJECT_SOURCE_DIR}/src/mainform.cpp ${PROJECT_SOURCE_DIR}/src/popplerdialog.cpp ${MOC_SRCS} ${UI_HEADERS} ${PROJECT_SOURCE_DIR}/src/translations/yagf_pl.ts)
qt4_add_translation(${CMAKE_BINARY_DIR}/yagf_uk.qm ${PROJECT_SOURCE_DIR}/src/mainform.cpp ${PROJECT_SOURCE_DIR}/src/popplerdialog.cpp ${MOC_SRCS} ${UI_HEADERS} ${PROJECT_SOURCE_DIR}/src/translations/yagf_uk.ts)
#QT4_CREATE_TRANSLATION(yagf_ru.qm src/mainform.cpp ${MOC_SRCS} ${UI_HEADERS} src/yagf_ru.ts)
#set(CMAKE_INSTALL_PREFIX /usr/)
install_targets(/bin/ yagf)
if (CMAKE_SIZEOF_VOID_P EQUAL 8)
        set (LIB_PATH_SUFFIX 64)
        set_property (GLOBAL PROPERTY FIND_LIBRARY_USE_LIB64_PATHS TRUE)
endif(CMAKE_SIZEOF_VOID_P EQUAL 8)
install_targets(/lib${LIB_PATH_SUFFIX}/yagf xspreload)
install(FILES ${QM_FILES} DESTINATION ${QML_DESTINATION})
#install(FILES COPYING DESCRIPTION README AUTHORS ChangeLog DESTINATION share/yagf/)
install(FILES yagf.png DESTINATION share/pixmaps/)
install(FILES yagf.png DESTINATION share/icons/hicolor/96x96/apps/)
install(FILES YAGF.desktop DESTINATION share/applications/)

#set(CPACK_PACKAGE_FILE_NAME yagf)
set(CPACK_PACKAGE_VENDOR "Andrei Borovsky, anb@symmetrica.net")
set(CPACK_PACKAGE_CONTACT ${CPACK_PACKAGE_VENDOR})
set(CPACK_SYSTEM_NAME "i586")
set(CPACK_BINARY_DEB ON)
set(CPACK_BINARY_RPM ON)
set(CPACK_BINARY_STGZ ON)
set(CPACK_BINARY_TGZ OFF)
set(CPACK_BINARY_TZ OFF)
set(CPACK_BINARY_TBZ2 OFF)
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Graphical front-end for cuneiform and tesseract OCR tools")
set(CPACK_PACKAGE_VERSION 0.9.1)
set(CPACK_PACKAGE_VERSION_MAJOR "0")
set(CPACK_PACKAGE_VERSION_MINOR "9")
set(CPACK_PACKAGE_VERSION_PATCH "1")
set(CPACK_STRIP_FILES bin/yagf bin/libyagfpreload)
set(CPACK_SOURCE_TBZ2 "OFF")
set(CPACK_SOURCE_TGZ "ON")
set(CPACK_SOURCE_TZ "OFF")
set(CPACK_SOURCE_INSTALLED_DIRECTORIES "${CMAKE_SOURCE_DIR}/yagf-${CPACK_PACKAGE_VERSION}/;/")
set(CPACK_RESOURCE_FILE_LICENSE ${CMAKE_SOURCE_DIR}/COPYING)
set(CPACK_PACKAGE_DESCRIPTION_FILE ${CMAKE_SOURCE_DIR}/DESCRIPTION)
set(CPACK_RESOURCE_FILE_README ${CMAKE_SOURCE_DIR}/README)
set(DEBIAN_PACKAGE_SECTION "text processing")
set(CPACK_RPM_PACKAGE_LICENSE "GPL v.3.0")
set (CPACK_RPM_PACKAGE_REQUIRES "libqt > 4.5")
include(CPack)


